package com.sjzd.meeting.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sjzd.meeting.dao.RoleDAO;
import com.sjzd.meeting.pojo.Role;
import com.sjzd.meeting.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoleService implements IRoleService {

    @Autowired
    private RoleDAO roleDAO;


    @Override
    public PageInfo<Role> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Role> roles = roleDAO.findAll();
        PageInfo<Role> pageInfo = new PageInfo<>(roles, pageSize);
        return pageInfo;
    }


    @Transactional
    @Override
    public int deleteById(Integer id) {
        return roleDAO.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<Role> findByCondition(String rname, Integer status, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Role> roles = roleDAO.findByCondition(rname, status);
        PageInfo<Role> pageInfo = new PageInfo<>(roles, pageSize);
        return pageInfo;
    }


    @Transactional
    @Override
    public int update(Role role) {
        return roleDAO.updateByPrimaryKey(role);
    }

    @Override
    public Role findById(Integer id) {
        return roleDAO.selectByPrimaryKey(id);
    }

    @Override
    public int save(Role role) {
        return roleDAO.insert(role);
    }
}
